package service

import (
	"context"
	"fmt"
	appsV1 "k8s.io/api/apps/v1"
	metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
)

func GetReplicaSetList(clientSet *kubernetes.Clientset, namespaceName string, deploymentName string) (replicaSetList *appsV1.ReplicaSetList, err error) {
	labelSelector := fmt.Sprintf("app=%s", deploymentName)
	replicaSetList, err = clientSet.AppsV1().ReplicaSets(namespaceName).List(context.TODO(), metaV1.ListOptions{LabelSelector: labelSelector})
	if err != nil {
		return replicaSetList, err
	}
	return replicaSetList, nil
}

func GetReplicaSet(clientSet *kubernetes.Clientset, namespaceName string, replicaSetName string) (replicaSetInfo *appsV1.ReplicaSet, err error) {
	replicaSetInfo, err = clientSet.AppsV1().ReplicaSets(namespaceName).Get(context.TODO(), replicaSetName, metaV1.GetOptions{})
	if err != nil {
		return replicaSetInfo, err
	}
	return replicaSetInfo, nil
}
